<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>我的成绩</el-breadcrumb-item>
      <el-breadcrumb-item>考试</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card>
      <!-- 作业列表 -->
      <!-- border加边框 -->
      <!-- stripe隔行变色 -->

      <el-table :data="testlist" style="width: 100%">
        <el-table-column label="考试ID" prop="examId"></el-table-column>
        <el-table-column label="考试名称" prop="name"></el-table-column>
        <el-table-column label="答题时间" prop="answerTime"></el-table-column>
        <el-table-column label="得分" prop="score"></el-table-column>
        <el-table-column align="right">
          <!-- 与后端联调时需要template, 可能 -->
          <template slot-scope="scope">
            <el-button type="success" @click="nav(scope.$index)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <!-- <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryinfo.pagenum"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="queryinfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>-->
    </el-card>
  </div>
</template>


<script>
export default {
  created() {
    this.getTestList()
  },
  data() {
    return {
      queryinfo: {
        query: '',
        pagenum: 1,
        pagesize: 2
      },
      testlist: [],
      uid: this.$store.state.userId,
      total: 0
    }
  },
  methods: {
    // 按钮跳转
    nav(index) {
      this.$router.push('/score/tcontent/' + this.testlist[index].examId)
      this.$store.commit('changeId', { id: this.testlist[index].examId })
    },

    // 获取所有作业基本信息,包括作业id号,考试的也要类似的接口
    async getTestList() {
     // 取出的data重命名为res
      const { data: res } = await this.$http.get('user/grade/getGrade', {
        params: {
          userId: this.uid,
          type: 1
        }
      })
      if (res.code !== 200) return this.$message.error(res.message)
      this.testlist = res.data //和之前的data不同

      // 时间处理，但其实最好是后端自己处理好
      for (var i = 0; i < this.testlist.length; i++) {
        // 结束时间
        this.testlist[i].answerTime = /\d{4}-\d{1,2}-\d{1,2}/g.exec(
          this.testlist[i].answerTime
        )[0]
      }

      console.log(this.testlist)
    }
  }
}
</script>

<style lang="less" scoped>
</style>